<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const arr = [1, [7], [9, 11, [22, [33], [0, [9, [9, [7]]]]]], 3, [5]]

    // console.log(arr.flat(Infinity))

    // 实现一个扁平化的方法
    /* const flat = (arr) => {
      return arr.reduce((acc, cur) => {
        return acc.concat(Array.isArray(cur) ? flat(cur) : cur)
      }, [])
    } */
    const flat = (arr, deep = 1) => {
      if (deep <= 0) return arr
      return arr.reduce((acc, cur) => {
        return acc.concat(Array.isArray(cur) ? flat(cur, deep - 1) : cur)
      }, [])
    }
    // 第二个参数支持深度，不传默认是 1 层
    // console.log(flat(arr, Infinity));

    console.log([...new Set(flat(arr, Infinity))].sort((prev, next) => prev - next))
  </script>
</body>

</html>